#pragma once
#ifndef _TERRAIN_H
#define _TERRAIN_H

#include <windows.h>
#include <GdiPlus.h>
#include <utility>
#include "../common/configure.h"
#include "../common/Ptr.hpp"
#include "Plane.h"

using namespace std;
using namespace Gdiplus;


class Terrain
{
private:
  MyMatrix< Plane > _blocks;
  MyMatrix< Vertex > _vertexs;
  
  UINT _width;
  UINT _height;
  float _altitude;

  void handle_surface_info ();
  void calc_and_smooth_normal ();
  void load_terrain (const WCHAR* file_name);
  void read_data (BitmapData& bitmapData);
  pair< int, int > _get_block (float x, float y) const;

public:
  Terrain (const WCHAR* file_name);

  uint width () const { return _width; }
  uint height () const { return _height; }
  float altitude () const { return _altitude; }

  float altitude (float x, float y) const;
  Normal3f normal (float x, float y) const;

  const MyMatrix< Plane >& planes () const { return _blocks; }
  const MyMatrix< Vertex >& vertexs () const { return _vertexs; }
  
};

#endif